package com.dz.Incubator.service.impl;

import com.dz.Incubator.dao.ServiceInfoDao;
import com.dz.Incubator.dto.ServiceInfoDto;
import com.dz.Incubator.entity.ServiceInfoEntity;
import com.dz.Incubator.service.ServiceInfoService;
import com.dz.Incubator.config.Pagination;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ServiceInfoServiceImpl implements ServiceInfoService {

    private static final Logger logger = LoggerFactory.getLogger(ServiceInfoService.class);

    @Autowired
    private ServiceInfoDao serviceInfoDao;

    @Override
    public ServiceInfoEntity insert(ServiceInfoEntity serviceInfoEntity) {
        serviceInfoDao.insert(serviceInfoEntity);

        return serviceInfoEntity;
    }

    @Override
    public ServiceInfoEntity update(ServiceInfoEntity serviceInfoEntity) {
        serviceInfoDao.update(serviceInfoEntity);

        return serviceInfoEntity;
    }

    @Override
    public Integer delete(Long id) {
        int ret = serviceInfoDao.delete(id);
        return ret;
    }

    @Override
    public List<ServiceInfoEntity> find(Long[] ids) {
        List<ServiceInfoEntity> datas = serviceInfoDao.find(ids);
        return datas;
    }

    @Override
    public ServiceInfoEntity get(Long id) {
        ServiceInfoEntity serviceInfoEntity = serviceInfoDao.get(id);
        return serviceInfoEntity;
    }

    @Override
    public List<ServiceInfoEntity> findAll() {
        List<ServiceInfoEntity> datas = serviceInfoDao.findAll();
        return datas;
    }

    @Override
    public Pagination findByPagination(Pagination pagination) {
        List<ServiceInfoEntity> datas = serviceInfoDao.findByPagination(pagination);
        pagination.setList(datas);
        return pagination;
    }

    @Override
    public List<ServiceInfoEntity> insertBatch(List<ServiceInfoEntity> list) {
        int ret = serviceInfoDao.insertBatch(list);
        return list;
    }

    @Override
    public List<ServiceInfoEntity> updateBatch(List<ServiceInfoEntity> list) {
        int ret = serviceInfoDao.updateBatch(list);
        return list;
    }

    @Override
    public List<Long> deleteBatch(Long[] ids) {
        int ret = serviceInfoDao.deleteBatch(ids);
        List<ServiceInfoEntity> datas = serviceInfoDao.find(ids);
        List<Long> list = new ArrayList<Long>();
        for (ServiceInfoEntity data : datas) {
            list.add(data.getId());
        }
        return list;
    }

    /**
     * 获取菜单信息
     *
     * @return
     */
    @Override
    public List<ServiceInfoDto> getMenu() {
        return this.serviceInfoDao.getMenu();
    }

    @Override
    public List<ServiceInfoEntity> findRecomend() {
        return this.serviceInfoDao.findRecomend();
    }

    @Override
    public List<ServiceInfoEntity> searchService(String key, int type) {
        key = "%" + key + "%";
        return this.serviceInfoDao.searchService(key, type);
    }
}